package com.dr.controller.admin;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dr.entity.Orderdetail;
import com.dr.entity.Orderinfo;
import com.dr.service.OrderinfoService;
import com.dr.util.LayUiResult;


@Controller
@RequestMapping("/admin/")
public class OrderinfoController{
	//注入service
	@Autowired
	private OrderinfoService orderinfoService;
	/**
	 * 全查
	 * @param p
	 * @return	以Map的方式返回查询到的数据和行数
	 */
	@RequestMapping(value = "/findOrderinfo.do",method = RequestMethod.GET)
	@ResponseBody//转为json格式数据
	public Map<String, Object> findOrderinfo(Orderinfo o) {
		//调用service
		List<Orderinfo> list = orderinfoService.AllOrderinfo(o);
		int count = orderinfoService.getCount(o);
		//返回结果都是以Map的方式返会给Layui所以返回值都是Map
		return LayUiResult.toClient("0", "succsee" , count, list);
	}
	/**
	 * 发货
	 * @param ids
	 * @return 返回
	 */
	@RequestMapping(value = "/updateOrderinfo.do",method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateOrderinfo(Orderinfo o) {
		//调用service
		int res = orderinfoService.updateOrderinfo(o);
		//返回结果
		return res>0 ? LayUiResult.toClient("0", "修改成功") : LayUiResult.toClient("1", "修改失败");
	}
	/**
	 * 查找
	 */
	@RequestMapping(value = "/findOrder.do")
	@ResponseBody
	public Map<String, Object> findOrder(String orderId) {
		List<Orderdetail> list = orderinfoService.findOrder(orderId);
		return LayUiResult.toClient("0", "succsee" , 0, list);
	}
}
